﻿Imports Models.Security

Namespace Security

    Public Class GeoTypes
        Private geoTypes As Generic.List(Of String)

        Sub New()
            geoTypes = New Generic.List(Of String)

            geoTypes.Add("MARKER")
            geoTypes.Add("POLYLINE")
            geoTypes.Add("CIRCLE")
            geoTypes.Add("POLYGON")
            geoTypes.Add("RECTANGLE")
        End Sub

        ''' <summary>
        ''' Sincronize GeoTypes
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub sincronize()

            Using oDB As New Data.BaseModel.BaseModelContainer("name=BaseModelContainer")

                '' add/update all GeoTypes
                Dim dbList As Generic.List(Of Data.BaseModel.GeoType) = (From r In oDB.GeoTypes Select r).ToList
                Dim found As Boolean
                For Each type As String In geoTypes

                    found = False

                    '' locate GeoType in DB
                    For Each dbGeoType As Data.BaseModel.GeoType In dbList
                        If dbGeoType.Code = type Then

                            found = True
                        End If
                    Next

                    '' create if not found
                    If Not found Then
                        Dim entity As New Data.BaseModel.GeoType
                        entity.Code = type

                        oDB.GeoTypes.AddObject(entity)
                    End If
                Next

                oDB.SaveChanges()

            End Using
        End Sub

    End Class
End Namespace